package com.yao.club.controller;

import com.yao.club.entity.result.ResponseEntity;
import com.yao.club.utils.ResponseUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@RestController
@RequestMapping("/app/update")
@Api(value = "版本更新模块", description = "版本更新模块", tags = "版本更新模块")
public class AppUpdateController {

    @ApiOperation(value = "检查版本更新", notes = "返回版本更新信息，客户端自行判断")
    @GetMapping("/check")
    public ResponseEntity<Object> checkUpdate() {
        // 构造更新信息
        UpdateInfo updateInfo = new UpdateInfo();
        updateInfo.setAppLevelId("11");
        updateInfo.setPlatform("ANDROID");
        updateInfo.setLatestVersion("2.2.4");
        updateInfo.setDownloadUrl("https://skl-prod.oss-cn-shenzhen.aliyuncs.com/zs-club-product-release_2_2_4.apk");
        updateInfo.setForceUpGrade(1);
        updateInfo.setMessage("检测到app有新的版本，立即更新！");
        updateInfo.setCreateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));

        return ResponseUtils.success(updateInfo);
    }

    // 更新信息实体类
    private static class UpdateInfo {
        private String appLevelId;
        private String platform;
        private String latestVersion;
        private String downloadUrl;
        private int forceUpGrade;
        private String message;
        private String createTime;

        // Getters and Setters
        public String getAppLevelId() {
            return appLevelId;
        }

        public void setAppLevelId(String appLevelId) {
            this.appLevelId = appLevelId;
        }

        public String getPlatform() {
            return platform;
        }

        public void setPlatform(String platform) {
            this.platform = platform;
        }

        public String getLatestVersion() {
            return latestVersion;
        }

        public void setLatestVersion(String latestVersion) {
            this.latestVersion = latestVersion;
        }

        public String getDownloadUrl() {
            return downloadUrl;
        }

        public void setDownloadUrl(String downloadUrl) {
            this.downloadUrl = downloadUrl;
        }

        public int getForceUpGrade() {
            return forceUpGrade;
        }

        public void setForceUpGrade(int forceUpGrade) {
            this.forceUpGrade = forceUpGrade;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public String getCreateTime() {
            return createTime;
        }

        public void setCreateTime(String createTime) {
            this.createTime = createTime;
        }
    }
}